home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1073 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. From: bglenden@colobus.aoc.nrao.edu (Brian Glendenning)
  2. Message-ID: <BGLENDEN.96Apr12135956@colobus.aoc.nrao.edu>
  3. X-Original-Date: 12 Apr 1996 19:59:56 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 14 Apr 96 11:52:54 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Use of standard exception classes
  9. Organization: National Radio Astronomy Observatory, Socorro NM
  10. References: <9604121530.AA08606@sun132.spd.dsccc.com>
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMXDnJOEDnX0m9pzZAQE5jwF8C3VygF8w9WaTVRaMancWgK+OHUHZOWud
  13.     OaJ/yRrSN+n1ShmDt2GGwoRD5n+vSeTq
  14.     =G9Zo
  15.  
  16. In a different topic, I'm confused about the different purpose ascribed to
  17. exceptions derived from logic_error:
  18.  
  19.     "The class logic_error defines the type of objects thrown as exceptions
  20.     to report errors presumably *detectable before the program executes*,
  21.     such as violations of logical preconditions or invariants."
  22.  
  23. and runtime_error:
  24.  
  25.     "The class runtime_error defines the type of objects thrown as
  26.     exceptions to report errors presumably only detectable when the program
  27.     executes." 
  28.  
  29. It seems to me that with this wording most exceptions should be derived from
  30. runtime_error. 
  31. However, basic_string<...>::remove(size_type pos = 0, size_type n = npos),
  32. for example, throws out_of_range (derived from logic error).
  33.  
  34. Unless the program only runs with manifest constants, it can't detect this
  35. problem before the program executs:
  36.     cin >> pos; mystring.remove(pos);
  37.  
  38. So why does it throw a logic_error rather than a runtime_error? Thanks!
  39.  
  40. (I'm also interested in learning whether it's a good idea to derive our
  41. exceptions from standard exceptions).
  42.  
  43. Brian
  44. -- 
  45.         Brian Glendenning - National Radio Astronomy Observatory
  46. bglenden@nrao.edu              Socorro NM               (505) 835-7347
  47. ---
  48. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  49. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  50. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  51. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  52. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  53.